﻿
Partial Public Class fs
    Public Shared Function workon_node(ByVal id As Int64,
                                       ByVal d As _do(Of node, eventComb)) As eventComb
        assert(Not d Is Nothing)
        Dim p As pointer(Of node) = Nothing
        Dim ec As eventComb = Nothing
        Dim dec As eventComb = Nothing
        Return New eventComb(Function() As Boolean
                                 p = New pointer(Of node)()
                                 ec = [get](id, p)
                                 Return waitfor(ec) AndAlso
                                        goto_next()
                             End Function,
                             Function() As Boolean
                                 If ec.end_result() AndAlso Not +p Is Nothing Then
                                     dec = d(+p)
                                     Return waitfor(dec) AndAlso
                                            goto_next()
                                 Else
                                     Return False
                                 End If
                             End Function,
                             Function() As Boolean
                                 Return dec.end_result() AndAlso
                                        goto_end()
                             End Function)
    End Function

    Public Shared Function workon_node(ByVal id As Int64,
                                       ByVal node As pointer(Of node),
                                       ByVal d As _do(Of node, eventComb)) As eventComb
        assert(Not d Is Nothing)
        Return workon_node(id,
                           Function(ByRef n As node) As eventComb
                               assert(Not n Is Nothing)
                               eva(node, n)
                               Return d(n)
                           End Function)
    End Function

    Public Shared Function name(ByVal id As Int64,
                                ByVal output As pointer(Of cached_string_property),
                                Optional ByVal node As pointer(Of node) = Nothing) As eventComb
        Return workon_node(id,
                           node,
                           Function(ByRef n As node) n.name(output))
    End Function

    Public Shared Function name(ByVal id As Int64,
                                ByVal output As pointer(Of String),
                                Optional ByVal node As pointer(Of node) = Nothing) As eventComb
        Return workon_node(id,
                           node,
                           Function(ByRef n As node) n.name(output))
    End Function

    Public Shared Function set_name(ByVal id As Int64,
                                    ByVal value As String,
                                    Optional ByVal node As pointer(Of node) = Nothing) As eventComb
        Return workon_node(id,
                           node,
                           Function(ByRef n As node) n.set_name(value))
    End Function
End Class
